package com.itheima.health.controller;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;

import com.itheima.health.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;


@RequestMapping("/setmeal")
@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @Autowired
    private AliOSSUtils ossUtils;
    /**
     * 分页查询
     *
     * @param queryPageBean
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        return setmealService.findPage(queryPageBean);
    }

    /**
     * 上传图片
     * @param imgFile
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile imgFile) throws IOException {

        String url = ossUtils.upload(imgFile);
        return new Result(true, MessageConst.UPLOAD_SUCCESS,url);
    }

    /**
     * 新增套餐
     * @param setmeal
     * @param checkgroupIds
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Setmeal setmeal,@RequestParam List<String> checkgroupIds) {
        return setmealService.add(setmeal,checkgroupIds);
    }
}
